package vcp.gui.forms;

import javax.swing.JPanel;

import vcp.common.IView;
import vcp.gui.components.VCPPanel;
import vcp.gui.forms.validators.NumericValidator;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JTextArea;
import javax.swing.JButton;

import client.Message;

import control.SimpleClient;
import db.parking.beans.Complaints;
import db.parking.beans.Orders;

import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Observable;
import java.util.Observer;
import javax.swing.border.TitledBorder;

public class ComplaintForm extends VCPPanel implements Observer,IView{
	
	
//public class OrderOccasionalForm extends VCPPanel implements Observer,IView {	
	private final JLabel lblComplaintFormError;
	private JTextField textOOID;
	private JTextField textOTitle;
	private SimpleClient client;
	private JTextArea textAreaODescr;
	private JButton btnSend;

	

	/**
	 * Create the panel.
	 */
	public ComplaintForm() {
		setBorder(new TitledBorder(null, "Complaints", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		JLabel lblOrderID = new JLabel("OrderID");
		lblComplaintFormError = new JLabel("");
		lblComplaintFormError.setForeground(Color.RED);		

		textOOID = new JTextField();
		textOOID.setColumns(10);

		JLabel lblCtitle = new JLabel("Title");

		textOTitle = new JTextField();
		textOTitle.setColumns(10);

		JLabel lblOdescr = new JLabel("Description");

		btnSend = new JButton("send");
		JScrollPane spane = new JScrollPane();

		GroupLayout groupLayout = new GroupLayout(this);
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
						.addComponent(btnSend)
						.addGroup(groupLayout.createSequentialGroup()
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addComponent(lblComplaintFormError)
								.addComponent(lblOdescr)
								.addComponent(lblCtitle)
								.addComponent(lblOrderID))
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
								.addComponent(spane, GroupLayout.DEFAULT_SIZE, 332, Short.MAX_VALUE)
								.addComponent(textOTitle, GroupLayout.DEFAULT_SIZE, 332, Short.MAX_VALUE)
								.addComponent(textOOID, GroupLayout.DEFAULT_SIZE, 332, Short.MAX_VALUE))))
					.addGap(31))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(8)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
								.addComponent(textOOID, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblOrderID))
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
								.addComponent(textOTitle, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblCtitle)))
						.addComponent(lblComplaintFormError))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(lblOdescr)
						.addComponent(spane, GroupLayout.PREFERRED_SIZE, 72, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(btnSend)
					.addContainerGap(118, Short.MAX_VALUE))
		);
		textAreaODescr = new JTextArea();
		spane.setViewportView(textAreaODescr);
		setLayout(groupLayout);
	}
	
	
	@Override
	public void update(Observable o, Object arg) {
		Message tempMsg = (Message)arg;  
	
		switch(tempMsg.getMsg())
		 {
		 	case "SubmitComplaint":
				if(tempMsg.isStatus())
				{
					JOptionPane.showMessageDialog(null , "Your Complaint have been Commited");
				}	
				else
				{
					JOptionPane.showMessageDialog(null,"Complaint has Failed: " + tempMsg.getStatusMsg(),"DATABASE ERROR",JOptionPane.ERROR_MESSAGE);
				}
				break;
		 }
	}
	
	
	public JTextField getTextOOID() {
		return textOOID;
	}

	public void setTextOOID(JTextField textOOID) {
		this.textOOID = textOOID;
	}

	public JTextField getTextOTitle() {
		return textOTitle;
	}

	public void setTextOTitle(JTextField textOTitle) {
		this.textOTitle = textOTitle;
	}

	public JTextArea getTextAreaODescr() {
		return textAreaODescr;
	}

	public void setTextAreaODescr(JTextArea textAreaODescr) {
		this.textAreaODescr = textAreaODescr;
	}

	public JButton getBtnSend() {
		return btnSend;
	}

	public void setBtnSend(JButton btnSend) {
		this.btnSend = btnSend;
	}

	public JLabel getLblComplaintFormError() {
		return lblComplaintFormError;
	}

	@Override
	public void addController(Object obj) {
		btnSend.addActionListener((ActionListener)obj);
		btnSend.setActionCommand("SubmitComplaint");
		
	}
	
}




